package com.smzd.projforge.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.smzd.core.dao.AbstractDao;
import com.smzd.core.mappers.IMapper;
import com.smzd.core.utils.db.SRPage;
import com.smzd.projforge.domain.DynaAttribute;
import com.smzd.projforge.domain.DynaClass;
import com.smzd.projforge.domain.Project;
import com.smzd.projforge.mappers.DynaAttributeMapper;

@Component
public class DynaAttributeDao extends AbstractDao<DynaAttribute> {
    @Autowired
    private DynaAttributeMapper mapper;

    @Override
    protected IMapper<DynaAttribute> getMapper() {
        return mapper;
    }

    public SRPage<DynaClass, DynaAttribute> getMTMAttributeCandidates(SRPage<DynaClass, DynaAttribute> page) {
        preparePage(page);
        List<DynaAttribute> elems = mapper.getMTMAttributeCandidates(page);
        page.setElems(elems);
        page.setTotalCount(elems.size());
        completePage(page);
        return page;
    }

    public List<DynaAttribute> getAttributesByProject(Project project) {
        SRPage<DynaClass, DynaAttribute> page = new SRPage<>();
        DynaClass qparam = new DynaClass();
        qparam.setScope(project);
        page.setScope(qparam);
        page.setPageSize(9999);
        List<DynaAttribute> props = mapper.listItemsByProjectId(page);
        return props;
    }

}
